package pl.mdziedzic.unittests.selenium;

import static org.fest.assertions.Assertions.assertThat;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class DomainRegistrationPage extends Page {

	public DomainRegistrationPage(WebDriver driver) {
		super(driver, "domeny-rejestracja-domen.html", "Domeny, Rejestracja domeny");
	}

	@Override
	public void verifyIsOnThePage() {
		super.verifyIsOnThePage();
		verifyTextPresent("Informacje na temat szukanych domen");
	}

	public void verifyDomainsAreAvailable(String... domains) {
		for (String domain : domains) {
			WebElement element = findById("domainName_" + domain);
			String attribute = element.getAttribute("class");

			assertThat(attribute).isEqualTo("DOMAIN_AVAILABLE");
		}
	}

	public void searchForDomain(String domainName) {
		insertText("domainName", domainName);
		click("single_submit");

		forceWait();
	}

	public BasketMainPage order(String domainName) {
		searchForDomain(domainName);
		clickAndSubmit("domainCheckbox_" + domainName);
		
		return new BasketMainPage(driver);
  }
	
}
